<template>
    <h2>添加页面</h2>
    <table>
        <tr>
            <td>
                投资名称:
            </td>
            <td>
                <input type="text" v-model="Name" id="Name" />
            </td>
        </tr>
        <tr>
            <td>
                总额度:
            </td>
            <td>
                <input type="text" v-model="Alls" id="Alls" />
            </td>
        </tr>
        <tr>
            <td>

            </td>
            <td>
                <input type="button" value="添加" @click="add">
            </td>
        </tr>
    </table>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import axios from "axios";

const Name = ref("");
const Alls = ref("");
const add = () => {
    if (!Name.value) {
        alert("投资名称不能为空");
        return;
    }
    axios.post('http://localhost:31285/api/Demo/Add', {
        Name: Name.value,
        Alls: Alls.value
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                location.href = '/Show'
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
        .catch(error => {
            console.log(error);
        })
}
</script>